﻿//************************************************************************//
//文件功能：API函数集合
//创 建 人：薄帅
//创建时间：2011年05月26日
//修 改 人：
//修改时间：
//************************************************************************//

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ProjBackEnd.Common.Helper
{
    public class Api
    {
        /// <summary>
        /// 通过设备句柄填充图像
        /// </summary>
        /// <param name="hdcDest">目标设备的句柄</param>
        /// <param name="nXDest">目标对象的左上角的X坐标</param>
        /// <param name="nYDest">目标对象的左上角的Y坐标</param>
        /// <param name="nWidth">目标对象的矩形的宽度</param>
        /// <param name="nHeight">目标对象的矩形的长度 </param>
        /// <param name="hdcSrc">源设备的句柄</param>
        /// <param name="nXSrc">源对象的左上角的X坐标</param>
        /// <param name="nYSrc">源对象的左上角的Y坐标</param>
        /// <param name="dwRop">光栅的操作值 </param>
        /// <returns></returns>
        [DllImportAttribute("gdi32.dll")]
        public static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, Int32 dwRop);

        [DllImportAttribute("gdi32.dll")]
        public static extern IntPtr CreateDC(
        string lpszDriver, // 驱动名称
        string lpszDevice, // 设备名称
        string lpszOutput, // 无用，可以设定位"NULL"
        IntPtr lpInitData // 任意的打印机数据
        );

        [DllImport("user32.dll")]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll")]
        public static extern IntPtr GetDesktopWindow();

        [DllImport("user32.dll")]
        public static extern IntPtr GetActiveWindow();

        [DllImport("user32.dll")]
        public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

        /// <summary>
        /// 判断是否连接Internet
        /// </summary>
        /// <param name="ConnectionDescription">连接方式</param>
        /// <param name="ReservedValue"></param>
        /// <returns>连接返回Ture，否则返回false</returns>
        [DllImport("wininet.dll")]
        public extern static bool InternetGetConnectedState(out int ConnectionDescription, int ReservedValue);

        [Serializable, StructLayout(LayoutKind.Sequential)]
        public struct RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }

        /// <summary>
        /// 窗体打开动态效果
        /// </summary>
        /// <param name="hwnd">窗体句柄</param>
        /// <param name="dwTime">动画时间</param>
        /// <param name="dwFlags">显示方式</param>
        /// <returns></returns>
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);

        /// <summary>
        /// 从左向右开屏
        /// </summary>
        public static readonly Int32 AW_HOR_POSITIVE = 0x00000001;
        /// <summary>
        /// 从右向左开屏
        /// </summary>
        public static readonly Int32 AW_HOR_NEGATIVE = 0x00000002;
        /// <summary>
        /// 从上向下开屏
        /// </summary>
        public static readonly Int32 AW_VER_POSITIVE = 0x00000004;
        /// <summary>
        /// 从下向上开屏
        /// </summary>
        public static readonly Int32 AW_VER_NEGATIVE = 0x00000008;
        /// <summary>
        /// 从中心向四周扩展,在关闭动画中则为从四周向中心收缩
        /// </summary>
        public static readonly Int32 AW_CENTER = 0x00000010;
        /// <summary>
        /// 关闭时候与前面的定义组合使用,如AW_HIDE or AW_CENTER
        /// </summary>
        public static readonly Int32 AW_HIDE = 0x00010000;
        /// <summary>
        /// 与1-5组合,开屏使用
        /// </summary>
        public static readonly Int32 AW_ACTIVATE = 0x00020000;
        /// <summary>
        /// 与1-5 + 6/7 组合,产生滑行效果
        /// </summary>
        public static readonly Int32 AW_SLIDE = 0x00040000;
        /// <summary>
        /// Win2000下使用,淡入淡出效果
        /// </summary>
        public static readonly Int32 AW_BLEND = 0x00080000;
        [DllImport("user32")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32")]
        public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        /// <summary>
        /// 写INI文件
        /// </summary>
        /// <param name="section">节点</param>
        /// <param name="key">键名</param>
        /// <param name="val">键值</param>
        /// <param name="filePath">文件名</param>
        /// <returns></returns>
        [DllImport("kernel32")]
        public static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
        /// <summary>
        /// 读INI文件
        /// </summary>
        /// <param name="section">节点</param>
        /// <param name="key">键名</param>
        /// <param name="def">如果 Key 值没有找到，则返回缺省的字符串的地址</param>
        /// <param name="retVal"> 返回字符串的缓冲区地址</param>
        /// <param name="size">缓冲区的长度 </param>
        /// <param name="filePath">文件名</param>
        /// <returns></returns>
        [DllImport("kernel32")]
        public static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowThreadProcessId(IntPtr hwnd, out   int ID);
    }
}
